#include <iostream>
#include <cstdio>
using namespace std;
struct a {
	int s,t,x;
};
a node[1007];
int main() {
	int n;
	while (~scanf("%d", &n)) {
		for (int i=0; i<n; ++i) {
			scanf("%d%d", &node[i].s, &node[i].t);
			if (node[i].t==1 || node[i].t==2) scanf("%d", &node[i].x);
		}
		int res=0;
		node[n].s=-1;
		int st=0;
		for (int i=0; i<n; ++i) {
			if (node[i].s>node[i+1].s) {
//				printf("st: %d i: %d\n", st, i);
				for (int t=i; t>=st; --t) {
					if (node[t].t==3) break;
					else if (node[t].t==4) {
						--t;
					}
					else if (node[t].t==1) res+=node[t].x;
					else if (node[t].t==2) res+=(t-st+1)*node[t].x;
				}
				st=i+1;
			}
		}
		printf("%d\n", res);
	}
	return 0;
} 
/*
9
1 1 300
2 2 400
2 3
2 2 500
1 1 1000
3 4
2 1 600
3 3
3 4
*/
